package com.cainaer.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cainaer.common.core.utils.DateUtils;
import com.cainaer.shop.domain.ShopLicense;
import com.cainaer.shop.mapper.ShopLicenseMapper;
import com.cainaer.shop.service.IShopLicenseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 商家入驻许可证 服务实现类
 * </p>
 *
 * @author Tina
 * @since 2020-09-03
 */
@Service
public class ShopLicenseServiceImpl extends ServiceImpl<ShopLicenseMapper, ShopLicense> implements IShopLicenseService {

    @Autowired
    private ShopLicenseMapper shopLicenseMapper;

    /**
     * 通过商家Id查询是否入住许可证
     *
     * @param shopId
     * @return
     */
    @Override
    public ShopLicense selectShopLicenseByShopId(Long shopId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("shop_id", shopId);
        return shopLicenseMapper.selectOne(queryWrapper);
    }

    /**
     * 编辑商家入驻许可证信息
     *
     * @param shopLicense
     * @return
     */
    @Override
    public Integer editShopLicenseByShopId(ShopLicense shopLicense) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("shop_id", shopLicense.getShopId());

        return shopLicenseMapper.update(shopLicense, queryWrapper);
    }

    /**
     * 新增商家入驻许可证信息
     *
     * @param shopLicense
     * @return
     */
    @Override
    public Integer insertShopLicense(ShopLicense shopLicense) {
        shopLicense.setCreateTime(DateUtils.getTime());
        return shopLicenseMapper.insert(shopLicense);
    }


}
